package com.fieldchain.ex.fa100.ui.money.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.access.Constant;
import com.fieldchain.ex.fa100.base.MyBaseActivity;
import com.fieldchain.ex.fa100.utils.screen.MyToast;
import com.google.gson.Gson;
import java.util.HashMap;
import com.fieldchain.ex.fa100.utils.net.access.HttpRequest;
import com.fieldchain.ex.fa100.utils.net.modle.StringRequest;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/10/22
 */
public class NewAddressActivity extends MyBaseActivity implements View.OnClickListener {
    private RelativeLayout reaBack;
    private TextView tvCenter;
    private EditText etAddress;
    private EditText etEmarks;
    private EditText etPwd;
    private TextView tvSure;
    private String id;

    @Override
    public void findView() {
        reaBack = findViewById(R.id.rea_back);
        tvCenter = findViewById(R.id.tv_center);
        etAddress = findViewById(R.id.et_address);
        etEmarks = findViewById(R.id.et_emarks);
        etPwd = findViewById(R.id.et_pwd);
        tvSure = findViewById(R.id.tv_sure);
    }

    @Override
    public void setValue() {
        id = getIntent().getStringExtra("coinId");
        reaBack.setOnClickListener(this);
        tvSure.setOnClickListener(this);
        tvCenter.setText("新建提币地址");
    }

    @Override
    public int getLayout() {
        return R.layout.activity_newaddress;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rea_back:
                finish();
                break;
            case R.id.tv_sure:
                addAddress();
                break;
        }
    }
    public void addAddress() {
        HashMap entry = new HashMap();
        entry.put("coinId", id);
        entry.put("walletAddress", etAddress.getText().toString());
        entry.put("walletLabel", etEmarks.getText().toString());
        entry.put("status", 1 + "");
        HttpRequest.getInstance().postRequest(new Gson().toJson(entry), Constant.addAddress + "?tpw=" + etPwd.getText().toString(), new StringRequest() {
            @Override
            public void onSucess(String str, int code, String msg) {
                if(code==200){
                    finish();
                }
                MyToast.show(msg);
            }

            @Override
            public void onFaild(Exception e) {

            }
        });
    }
}
